home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Development Platforms / CSMP Digests / csmp-v1-208.txt < prev    next >
Encoding:
Text File  |  1992-11-18  |  33.8 KB  |  1,050 lines  |  [TEXT/MPS ]

  1. C.S.M.P. Digest             Wed, 04 Nov 92       Volume 1 : Issue 208
  2.  
  3. Today's Topics:
  4.  
  5.     DogCow Calls
  6.     DYLAN
  7.     Animated Cursors...
  8.     Q: Stack munging in VBL tasks?
  9.     WDEF's and QuickDraw globals
  10.     How do I draw icl8's?
  11.     JPartialResources.{c,h}
  12.  
  13.  
  14.  
  15. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  16.  
  17. The digest is a collection of article threads from the internet newsgroup
  18. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  19. regularly and want an archive of the discussions.  If you don't know what a
  20. newsgroup is, you probably don't have access to it.  Ask your systems
  21. administrator(s) for details.  (This means you can't post questions to the
  22. digest.)
  23.  
  24. Each issue of the digest contains one or more sets of articles (called
  25. threads), with each set corresponding to a 'discussion' of a particular
  26. subject.  The articles are not edited; all articles included in this digest
  27. are in their original posted form (as received by our news server at
  28. cs.uoregon.edu).  Article threads are not added to the digest until the last
  29. article added to the thread is at least one month old (this is to ensure that
  30. the thread is dead before adding it to the digest).  Article threads that
  31. consist of only one message are generally not included in the digest.
  32.  
  33. The entire digest is available for anonymous ftp from ftp.cs.uoregon.edu
  34. [128.223.8.8] in the directory /pub/mac/csmp-digest.  Be sure to read the
  35. file /pub/mac/csmp-digest/README before downloading any files.  The most
  36. recent issues are available from sumex-aim.stanford.edu [36.44.0.6] in the
  37. directory /info-mac/digest/csmp.  If you don't have ftp capability, the sumex
  38. archive has a mail server; send a message with the text '$MACarch help' (no
  39. quotes) to LISTSERV@ricevm1.rice.edu for more information.
  40.  
  41. The digest is also available via email.  Just send a note saying that you
  42. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  43. automatically receive each new issue as it is created.  Sorry, back issues
  44. are not available through the mailing list.
  45.  
  46. Send administrative mail to mkelly@cs.uoregon.edu.
  47.  
  48.  
  49. -------------------------------------------------------
  50.  
  51. From: stud08@cc4.kuleuven.ac.be (Karl Pottie)
  52. Subject: DogCow Calls
  53. Date: 29 Sep 92 14:14:57 GMT
  54. Organization: K.U.Leuven - Academic Computing Center
  55.  
  56.  
  57. Moof !
  58.  
  59. As a true dogcow fan , I'd like to know what the toolbox calls
  60. enable/disableDogCow() do? On which systems are they available ?
  61.  
  62. Karl
  63.  
  64. +++++++++++++++++++++++++++
  65.  
  66. From: hammett@sbsu1.aukuni.ac.nz (Tim Hammett)
  67. Date: 29 Sep 92 22:03:35 GMT
  68. Organization: University of Auckland, New Zealand.
  69.  
  70. stud08@cc4.kuleuven.ac.be (Karl Pottie) writes:
  71. >As a true dogcow fan , I'd like to know what the toolbox calls
  72. >enable/disableDogCow() do? On which systems are they available ?
  73.  
  74. I think you'll find they're just aliases to the _Unimplemented trap,
  75. so they'll do whatever that trap does(probably nothing interesting).
  76. >From the MPW Traps.h file:
  77.  
  78. #define _Unimplemented                 0xA89F
  79. #define _InitDogCow                    0xA89F
  80. #define _EnableDogCow                  0xA89F
  81. #define _DisableDogCow                 0xA89F
  82. #define _Moof                          0xA89F
  83.  
  84. (Incidentally, I couldn't find any of the DogCow traps in any of the
  85. AIncludes files, a serious omission IMHO :-))
  86.  
  87. - --
  88. Tim Hammett, Botany Dept, Auckland University, New Zealand.
  89. t.hammett@aukuni.ac.nz   Phone: +64-9-373-7599 x8365    FAX: +64-9-373-7416
  90.  
  91. ---------------------------
  92.  
  93. From: freeze@ee.byu.edu (Jim Freeze)
  94. Subject: DYLAN
  95. Date: 17 Sep 92 15:41:07 GMT
  96. Organization: Brigham Young University, Provo UT USA
  97.  
  98.  
  99.  
  100. Has anyone heard of Apple's new OO language, DYLAN?
  101.  
  102. It stands for DYnamic LANguage.
  103.  
  104. If you have heard of it, I am trying to find out if is
  105. is available (i.e. can I get a compiler for it).
  106. and how much and where?
  107.  
  108. Thanks for any info
  109.  
  110. Jim
  111.  
  112. +++++++++++++++++++++++++++
  113.  
  114. From: squeegee@world.std.com (Stephen C. Gilardi)
  115. Date: 17 Sep 92 23:07:44 GMT
  116. Organization: SQ Software via The World Public Access UNIX, Brookline, MA
  117.  
  118. freeze@ee.byu.edu (Jim Freeze) writes:
  119.  
  120. >Has anyone heard of Apple's new OO language, DYLAN?
  121.  
  122. >It stands for DYnamic LANguage.
  123.  
  124. >If you have heard of it, I am trying to find out if is
  125. >is available (i.e. can I get a compiler for it).
  126. >and how much and where?
  127.  
  128. >Thanks for any info
  129.  
  130. >Jim
  131.  
  132. There's some discussion of it over in comp.lang.scheme from time to time.
  133. The only publicly available implementation of a Dylan-ish language that
  134. I know of is called Thomas.  It is written in Scheme and is available by
  135. anonymous ftp from either "crl.dec.com" or "ftp.crl.dec.com" (I don't
  136. remember which).  The following is from the README:
  137.  
  138. Comments, questions, suggestions, help, etc. should be directed to:
  139.           info-thomas@crl.dec.com
  140. Requests to be added to this mailing list should be sent to:
  141.           info-thomas-request@crl.dec.com
  142.  
  143. It runs under Gambit Scheme for example on the Mac.
  144.  
  145. Good Luck!
  146.  
  147. - --Steve
  148. squeegee@world.std.com
  149.  
  150. +++++++++++++++++++++++++++
  151.  
  152. From: ksand@apple.com (Kent Sandvik)
  153. Date: 18 Sep 92 17:33:38 GMT
  154. Organization: Apple
  155.  
  156. In article <t!#@byu.edu>, freeze@ee.byu.edu (Jim Freeze) wrote:
  157.  Has anyone heard of Apple's new OO language, DYLAN?
  158. > It stands for DYnamic LANguage.
  159. > If you have heard of it, I am trying to find out if is
  160. > is available (i.e. can I get a compiler for it).
  161. > and how much and where?
  162.  
  163. People are working on reference versions, I actually saw that
  164. DEC posted the first one, called Thomas :-). It's available 
  165. from ftp: crl.dec.com:pub/DEC/Thomas. Works on top of various
  166. PD Scheme systems, not fast, but it's more for testing out the
  167. language concepts.
  168.  
  169. Kent Sandvik
  170. who thinks it's time to get out a decent language to developers out there.
  171.  
  172. "You should really just relax" -MST3K
  173. - -------------------
  174. Kent Sandvik (UUCP: ....!apple!ksand; INTERNET: ksand@apple.com)
  175. DISCLAIMER: Private activities on the Net.
  176.  
  177. +++++++++++++++++++++++++++
  178.  
  179. From: joswig@informatik.uni-hamburg.de (Rainer Joswig)
  180. Date: 23 Sep 92 16:39:38 GMT
  181. Organization: University of Hamburg, FRG
  182.  
  183. In article <t!#@byu.edu>, freeze@ee.byu.edu (Jim Freeze) wrote:
  184. > Has anyone heard of Apple's new OO language, DYLAN?
  185.  
  186. You can find Information about Dylan in the
  187. directory /pub/dylan on the ftp server cambridge.apple.com .
  188. There is also the first Dylan implementation named Thomas.
  189. In this directory you will find an faq list about Dylan.
  190. There you can read about the new mailing list info-dylan.
  191. Sometime near there should be a newsgroup comp.lang.dylan .
  192.  
  193. Rainer Joswig
  194. Email: joswig@informatik.uni-hamburg.de
  195.  
  196. ---------------------------
  197.  
  198. From: pcw@access.digex.com (Peter Wayner)
  199. Subject: Animated Cursors...
  200. Date: 17 Sep 92 22:48:34 GMT
  201. Organization: Express Access Online Communications, Greenbelt, MD USA
  202.  
  203. Can anyone point me toward the right way
  204. to install an animated cursor? 
  205.  
  206. Thanks,
  207.  
  208. Peter Wayner
  209. (wayner@access.digex.com)
  210.  
  211. +++++++++++++++++++++++++++
  212.  
  213. From: chuck@gte.com (Chuck Hoffman)
  214. Date: 18 Sep 92 14:07:27 GMT
  215. Organization: GTE Laboratories
  216.  
  217. In article <1992Sep17.224834.24358@access.digex.com>, pcw@access.digex.com
  218. (Peter Wayner) wrote:
  219. > Can anyone point me toward the right way
  220. > to install an animated cursor? 
  221.  
  222. Create the several cursor resources you need which will make up your
  223. animation.  Then create an 'acur' resource which is a list of the cursor
  224. id's.  Then somewhere in your program get the 'acur' resource, then use
  225. SetCursor from time to time to switch from one cursor id to the next, as
  226. listed in the 'acur'.
  227.  
  228. Someone advised recently that it could also be done through the vertical
  229. retrace manager, but someone else pointed out that this would hide from the
  230. user the effect of speeding up and slowing down which the calls from within
  231. the program code would reveal.
  232.  
  233. Chuck Hoffman
  234. chuck@gte.com
  235. GTE Laboratories, Waltham, Massachusetts, USA
  236. (617) 466-2131
  237. =====================================
  238. I'm not sure why we're here, but I am sure that while we're here we're
  239. supposed to help each other.
  240. =====================================
  241.  
  242. +++++++++++++++++++++++++++
  243.  
  244. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  245. Date: 24 Sep 92 01:08:27 GMT
  246. Organization: Kalamazoo College
  247.  
  248. winer@husc8.harvard.edu (Adam Winer) writes:
  249. >mxmora@unix.SRI.COM (Matt Mora) writes:
  250. >>chuck@gte.com (Chuck Hoffman) writes:
  251. >>>
  252. >>>[You can do cursor animation from inside a VBL task]
  253. >>
  254. >>The key is to have the vbl task check a counter that the program increments.
  255. >>The vbl would then show the true performance. And on the occasion that
  256. >>the program gets stuck in an endless loop, the vbl could detect that
  257. >>and either trigger a fail routine or jump to it.
  258. >
  259. >This strikes me as overkill: if the vbl task is going to refer back to
  260. >a program counter, just change the cursor from within the normal flow
  261. >of your program.
  262.  
  263. Agreed, Adam.
  264.  
  265. Additionally, Matt, I'm not sure if it would even be remotely possible
  266. for a VBL task to break a program out of its endless loop.  You
  267. certainly don't want to jump straight to the fail routine;  you're still
  268. servicing the interrupt.  The only way that I can see is to find the PC
  269. from wherever the interrupt code hid it, check to be sure it's in your
  270. heap, and modify the code about to be executed by writing a "JMP fail"
  271. over it.  Don't forget to save the original instructions somewhere so
  272. you can restore them, and to flush the instruction cache.  :-/
  273.  
  274. I'm sure there are ickier ways to crash-proof a program than using a
  275. periodic interrupt to save you from infinite loops, but at the moment
  276. I can't think of any...
  277. - -- 
  278.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  279.  "I don't think we should have to have them wandering the streets
  280.   frightening women and people."                            - Pat Buchanan
  281.  
  282. +++++++++++++++++++++++++++
  283.  
  284. From: urlichs@smurf.sub.org (Matthias Urlichs)
  285. Date: 30 Sep 92 00:57:07 GMT
  286. Organization: University of Karlsruhe, FRG
  287.  
  288. In comp.sys.mac.programmer, article <38774@unix.SRI.COM>,
  289.   mxmora@unix.SRI.COM (Matt Mora) writes:
  290. > The key is to have the vbl task check a counter that the program increments.
  291. > The vbl would then show the true performance. And on the occasion that
  292. > the program gets stuck in an endless loop, the vbl could detect that
  293. > and either trigger a fail routine or jump to it.
  294. I don't think that jumping out of a VBL or quitting an application from
  295. under it would be that good an idea. Memory may be in an inconsistent state, 
  296. the interrupt level is not zero, and the VBL queue is marked busy. Undoing
  297. all of this manually is a big compatibility risk.
  298.  
  299. If your application hangs, it's a bug. I respectfully suggest that you debug
  300. your applications before shipping them to customers.  ;-)
  301.  
  302. - -- 
  303. Bradley's Bromide:
  304.         If computers get too powerful, we can organize them into a
  305.         committee -- that will do them in.
  306. - -- 
  307. Matthias Urlichs  --  urlichs@smurf.sub.org -- urlichs@smurf.ira.uka.de   /(o\
  308. Humboldtstrasse 7 -- 7500 Karlsruhe 1 -- Germany  --  +49-721-9612521     \o)/
  309.  
  310. ---------------------------
  311.  
  312. From: mccabe@hatteras.cs.unc.edu (Daniel McCabe)
  313. Subject: Q: Stack munging in VBL tasks?
  314. Date: 22 Sep 92 16:48:07 GMT
  315.  
  316.  
  317. Is there a kosher way of finding out what the stack pointer was immediately
  318. prior to the VBL interrupt? I want to write some code which performs a 
  319. task switch in a VBL task, but to do that, I need to know where the SP
  320. was prior to the VBL interrupt. I haven't found this info in either
  321. IM or in Tech Notes. If I missed it, any pointers are appreciated.
  322.  
  323. Thanx in advance,
  324. danm
  325.  
  326. +++++++++++++++++++++++++++
  327.  
  328. From: keith@taligent.com (Keith Rollin)
  329. Date: 23 Sep 92 19:42:44 GMT
  330. Organization: Taligent
  331.  
  332. In article <15544@borg.cs.unc.edu>, mccabe@hatteras.cs.unc.edu (Daniel
  333. McCabe) wrote:
  334. > Is there a kosher way of finding out what the stack pointer was immediately
  335. > prior to the VBL interrupt? I want to write some code which performs a 
  336. > task switch in a VBL task, but to do that, I need to know where the SP
  337. > was prior to the VBL interrupt. I haven't found this info in either
  338. > IM or in Tech Notes. If I missed it, any pointers are appreciated.
  339.  
  340. MPW Shell does something like this. The details are sketchy, but I think I
  341. have the right idea. MPW Shell installs a VBL task and then goes into a
  342. tight loop:
  343.  
  344.         TightLoop     bra.s TightLoop
  345.  
  346. When it gets triggered 1/60 of a second later, the VBL task then looks for
  347. the address of TightLoop on the stack. From that information, it determines
  348. what you are asking for.
  349.  
  350. Why does MPW do this? I believe it's so you can press Cmd-Period to break
  351. out of hung tools (it also installs a VBL to look for Cmd-Period).
  352.  
  353. - -----
  354. Keith Rollin
  355. Phantom Programmer
  356. Taligent, Inc.
  357.  
  358. +++++++++++++++++++++++++++
  359.  
  360. From: phils@chaos.cs.brandeis.edu (Phil Shapiro)
  361. Organization: Symantec Corp.
  362. Date: Fri, 25 Sep 1992 15:10:16 GMT
  363.  
  364. >>>>> On Wed, 23 Sep 1992 19:42:44 GMT, keith@taligent.com (Keith Rollin) said:
  365.  
  366.  > Why does MPW do this? I believe it's so you can press Cmd-Period to
  367.  > break out of hung tools (it also installs a VBL to look for
  368.  > Cmd-Period).
  369.  
  370. Hmm, last time I checked MPW installs a handler in the low memory auto
  371. interrupt vector; kind of an odd way to check for command-period if
  372. you ask me. I suppose this would enable MPW to remove all VBLs
  373. belonging to the stopped tool, though...
  374.  
  375.     -phil
  376. - --
  377.    Phil Shapiro                                   Software Engineer
  378.    Language Products Group                     Symantec Corporation
  379.            Internet: phils@cs.brandeis.edu
  380.  
  381. ---------------------------
  382.  
  383. From: ww10+@andrew.cmu.edu (William Conrad Wojciechowski)
  384. Subject: WDEF's and QuickDraw globals
  385. Date: 30 Sep 92 09:03:43 GMT
  386. Organization: H&SS Dean's Office, Carnegie Mellon, Pittsburgh, PA
  387.  
  388. I was wondering if anybody has a reliable solution for accessing
  389. QuickDraw globals in a WDEF.  Right now, I am creating patterns and
  390. other needed globals on the fly.  This is a safe method but, I would
  391. like to know if there is a safe way to directly access the QuickDraw
  392. globals. 
  393.  
  394. Thanks in advance.
  395.  
  396. - - Will 
  397.  
  398. +++++++++++++++++++++++++++
  399.  
  400. From: keith@taligent.com (Keith Rollin)
  401. Organization: Taligent
  402. Date: Wed, 30 Sep 1992 20:53:04 GMT
  403.  
  404. In article <gemRrjq00iVgQ1o2Yn@andrew.cmu.edu>, ww10+@andrew.cmu.edu
  405. (William Conrad Wojciechowski) wrote:
  406. > I was wondering if anybody has a reliable solution for accessing
  407. > QuickDraw globals in a WDEF.  Right now, I am creating patterns and
  408. > other needed globals on the fly.  This is a safe method but, I would
  409. > like to know if there is a safe way to directly access the QuickDraw
  410. > globals. 
  411.  
  412. I usually use routines like the following:
  413.  
  414. typedef struct {
  415.     char        privates[76];
  416.     long        randSeed;
  417.     BitMap        screenBits;
  418.     Cursor        arrow;
  419.     Pattern        dkGray;
  420.     Pattern        ltGray;
  421.     Pattern        gray;
  422.     Pattern        black;
  423.     Pattern        white;
  424.     GrafPtr        thePort;
  425. } QDGlobals;
  426.  
  427. long*    GetA5(void) = 0x200D;            // move.l    A5,D0
  428.  
  429. Pattern*    GetWhitePattern()
  430. {
  431.     long*        curA5;
  432.     curA5 = GetA5();
  433.     return (Pattern*) (*curA5 - (sizeof(QDGlobals) - sizeof(Ptr)) + 
  434.                     offsetof(QDGlobals, white));
  435. }
  436.  
  437. - -----
  438. Keith Rollin
  439. Phantom Programmer
  440. Taligent, Inc.
  441.  
  442. ---------------------------
  443.  
  444. From: sho@bohr.physics.purdue.edu (Sho Kuwamoto)
  445. Subject: How do I draw icl8's?
  446. Date: 30 Sep 92 18:40:13 GMT
  447. Organization: Purdue University Physics Department
  448.  
  449. IM VI gives the following useful info:
  450.     [PlotIcon and PlotCIcon] will not draw any icons that
  451.     are defined by the icon resources new to system 
  452.     software 7.0 -- namely, the 'ics#', 'icl4', 'ics4',
  453.     'icl8', and 'ics8' resources.
  454.  
  455. Unfortunately, IM VI does not seem to say how one goes about
  456. drawing these icons.  Well, how *do* I draw these types of
  457. icons?  Also, is there an easy way for me to hilight the
  458. icons in the same way that the Finder does?
  459.  
  460. - -Sho
  461. - --
  462. sho@physics.purdue.edu
  463.  
  464. +++++++++++++++++++++++++++
  465.  
  466. From: sainaney@unixg.ubc.ca (Narayan R. Sainaney)
  467. Organization: University of British Columbia, Vancouver, B.C., Canada
  468. Date: Thu, 1 Oct 1992 00:24:40 GMT
  469.  
  470. In article <8352@dirac.physics.purdue.edu> sho@bohr.physics.purdue.edu (Sho Kuwamoto) writes:
  471. >IM VI gives the following useful info:
  472. >    [PlotIcon and PlotCIcon] will not draw any icons that
  473. >    are defined by the icon resources new to system 
  474. >    software 7.0 -- namely, the 'ics#', 'icl4', 'ics4',
  475. >    'icl8', and 'ics8' resources.
  476. >
  477. >Unfortunately, IM VI does not seem to say how one goes about
  478. >drawing these icons.  Well, how *do* I draw these types of
  479. >icons?  Also, is there an easy way for me to hilight the
  480. >icons in the same way that the Finder does?
  481. >
  482. >-Sho
  483. >--
  484. >sho@physics.purdue.edu
  485.  
  486.     You are in luck. I just finised working on Luanch Pad (a 
  487. shareware app) that makes extensive use of PlotIconID which is very
  488. well documented in APDA tech Note 306. The routine call is:
  489.  
  490. err:= PlotIconID (theRect,align,transform,theResID)
  491.  
  492. where align and transform allow you to do neat stuff like center/
  493. left or right justify it and transfor it (launched etc etc)
  494.  
  495. The interface file is at the end of the tech note and it contains
  496. all the values possible for align and transform (integers). The inline
  497. function is:
  498.  
  499. function PlotIconID(theRect:Rect;align:Integer;transform:integer;
  500.                     theResID:Integer):OsErr;
  501. inline
  502.  $303C,$0500,$ABC9
  503.  
  504. hope this helps. 
  505. sainaney@unixg.ubc.ca
  506. PS: To do a simple plot, use 0,0 for align and transform.
  507.  
  508.  
  509. ---------------------------
  510.  
  511. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  512. Subject: JPartialResources.{c,h}
  513. Date: 24 Sep 92 23:24:23 GMT
  514. Organization: Kalamazoo College
  515.  
  516. Following is my current working version of "Jamie's Partial Resources,"
  517. glue that makes the system-7 partial resource calls work under any
  518. system.  I'm posting this here 'cause I haven't seen partial-resource
  519. glue anywhere else, and I thought it might be useful.
  520.  
  521. Please note that this is not a final copy--jSetResourceSize() doesn't do
  522. anything, jWritePartialResource() has never been tested, and
  523. jReadPartialResource() has been extensively tested for all of forty-five
  524. minutes.  They're working fine for me so far, though (and if there were
  525. anything seriously wrong, I'm sure the crashes would be spectacular).
  526. If and when I get it working more solidly, I'll post the code here.
  527. (Don't expect jSetResourceSize() though--an efficient implementation is
  528. far harder for that function than for the other two, and I don't need
  529. it yet, so it's way down low on my priority list.)
  530.  
  531. Usage is simple:  whenever you might call ReadPartialResource or
  532. WritePartialResource, call jReadPartialResource or jWritePartialResource
  533. instead.  To get the resource handle to pass to them, SetResLoad(FALSE)
  534. and GetResource(type, id).  (Oh, and SetResLoad(TRUE) again, of course.)
  535. - --
  536.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  537.  Was bringt mich nicht um...
  538.  
  539.  
  540.  
  541. /*
  542.  * JPartialResources.h
  543.  *
  544.  * Jamie's partial resource calls that work under any system.
  545.  * (c) Copyright 1992 by Jamie R. McCarthy.  All rights reserved.
  546.  * This code can be both distributed and used freely.
  547.  *
  548.  */
  549.  
  550.  
  551.  
  552. /******************************/
  553.  
  554. extern Boolean partialResourceCallsAvailable;
  555.  
  556. /******************************/
  557.  
  558.  
  559.  
  560. void jReadPartialResource(Handle theResource, long offset, void *buffer, long count);
  561. void jWritePartialResource(Handle theResource, long offset, void *buffer, long count);
  562. void jSetResourceSize(Handle theResource, long size);
  563.  
  564.  
  565.  
  566.  
  567.  
  568. /*
  569.  * JPartialResources.c
  570.  *
  571.  * Jamie's partial resource calls that work under any system.
  572.  * (c) Copyright 1992 by Jamie R. McCarthy.  All rights reserved.
  573.  * This code can be both distributed and used freely.
  574.  * Internet: k044477@kzoo.edu       AppleLink: j.mccarthy
  575.  * Telephone:  800-421-4157 or US 616-665-7075 (9:00-5:00 Eastern time)
  576.  * I'm releasing this code with the hope that someone will get something
  577.  * out of it.  Feedback of any sort, even just letting me know that you're
  578.  * using it, is greatly appreciated!
  579.  *
  580.  *
  581.  * "Be aware that having a copy of a resource in memory when you are using
  582.  *  the partial resource routines may cause problems.  If you have modified
  583.  *  the copy in memory and then access the resource on disk using either
  584.  *  the ReadPartialResource or WritePartialResource procedure, you will
  585.  *  lose changes made to the copy in memory."  - IM VI, 13-21
  586.  *
  587.  * By "copy in memory," this refers to having the entire resource loaded in.
  588.  * What it's saying is that ReadPartialResource and WritePartialResource
  589.  * consider themselves free to purge (and maybe reload) the resource
  590.  * handle.  Incidentally, my routines don't do that--they read directly from
  591.  * disk--so if you're under system 6, your copy of the resource is safe.
  592.  * (Memory may be moved, however, so if the resource is purgeable, it may
  593.  * be purged.)
  594.  *
  595.  *
  596.  * "...there's really no reason to access resources directly."  - IM IV-16.
  597.  *
  598.  * Yeah right.
  599.  *
  600.  */
  601.  
  602.  
  603.  
  604. /******************************/
  605.  
  606. #include "JPartialResources.h"
  607.  
  608. /******************************/
  609.  
  610. #include <GestaltEqu.h>
  611.  
  612. /******************************/
  613.  
  614. #define kUninitializedFlag (42)
  615. Boolean partialResourceCallsAreAvailable = kUninitializedFlag;
  616.  
  617. void determineWhetherPRCallsAreAvailable(void);
  618.  
  619. /******************************/
  620.  
  621. typedef struct {
  622.    unsigned long     offsetToRsrcData;
  623.    unsigned long     offsetToRsrcMap;
  624.    unsigned long     lengthOfRsrcData;
  625.    unsigned long     lengthOfRsrcMap;
  626. } rsrcForkHeader;
  627.  
  628. typedef struct {
  629.    short             rsrcID;
  630.    short             offsetToRsrcName;
  631.    unsigned long     rsrcAttrs : 8;
  632.    unsigned long     offsetToRsrcData : 24;
  633.    Handle            rsrcHndl;
  634. } rsrcReference;
  635.  
  636. struct rsrcMap;
  637. typedef struct rsrcMap rsrcMap, *rsrcMapPtr, **rsrcMapHndl;
  638. struct rsrcMap {
  639.    rsrcForkHeader    copyOfRsrcForkHeader;
  640.    rsrcMapHndl       nextRsrcMapHndl;
  641.    short             fileRefNum;
  642.    short             fileAttrs;
  643.    unsigned short    offsetToTypeList;
  644.    unsigned short    offsetToNameList;
  645. } ;
  646.  
  647. /******************************/
  648.  
  649.       /*
  650.        * Lower-level internal functions.
  651.        */
  652.       
  653.    /*
  654.     * Just as _HomeResFile returns the refNum of a resource's file,
  655.     * so does getHomeRsrcMap() return a pointer to the resource
  656.     * file's map.  Warning--any calls that may move memory,
  657.     * including system memory, invalidate the pointer!
  658.     */
  659. rsrcMapPtr getHomeRsrcMap(Handle theResource);
  660.  
  661.    /*
  662.     * This uses _RsrcMapEntry and getHomeRsrcMap() to find the
  663.     * offset from the beginning of a resource fork to the start of
  664.     * a resource's reference.
  665.     */
  666. long getRsrcRefOffsetIntoFile(Handle theResource);
  667.  
  668. /******************************/
  669.  
  670.       /*
  671.        * Higher-level internal functions.
  672.        */
  673.       
  674.    /*
  675.     * This uses getRsrcRefOffsetIntoFile() and FSRead() to find
  676.     * the offset from the beginning of a resource fork to the start
  677.     * of a resource's data.  The offset points to the data itself,
  678.     * which is just past the longword that tells its size.  If you
  679.     * happen to want the size too, use _SizeResource.
  680.     */
  681. long getRsrcDataOffsetIntoFile(Handle theResource);
  682.  
  683. long getRsrcFileMark(Handle theResource);
  684. void setRsrcFileMark(Handle theResource, long newMark);
  685.  
  686. /******************************/
  687.  
  688.  
  689.  
  690. void jReadPartialResource(Handle theResource, long offset, void *buffer, long count)
  691. {
  692.    if (partialResourceCallsAreAvailable == kUninitializedFlag) {
  693.       determineWhetherPRCallsAreAvailable();
  694.    }
  695.    
  696.    if (partialResourceCallsAreAvailable) {
  697.       ReadPartialResource(theResource, offset, buffer, count);
  698.    } else {
  699.       
  700.       long theRsrcDataOffset;
  701.       long theRsrcDataLength;
  702.       OSErr theErr;
  703.       long oldMark;
  704.       
  705.       oldMark = getRsrcFileMark(theResource);
  706.       theRsrcDataOffset = getRsrcDataOffsetIntoFile(theResource);
  707.       if (theRsrcDataOffset < 0) return ;
  708.       setRsrcFileMark(theResource, theRsrcDataOffset + offset);
  709.       theErr = FSRead( HomeResFile(theResource), &count, buffer );
  710.       setRsrcFileMark(theResource, oldMark);
  711.       
  712.    }
  713. }
  714.  
  715.  
  716.  
  717. void jWritePartialResource(Handle theResource, long offset, void *buffer, long count)
  718. {
  719.    if (partialResourceCallsAreAvailable == kUninitializedFlag) {
  720.       determineWhetherPRCallsAreAvailable();
  721.    }
  722.    
  723.       /*
  724.        * Disallow writing past the end of the resource;
  725.        * try to increase its size if possible.
  726.        */
  727.    if (SizeResource(theResource) < offset+count) {
  728.       jSetResourceSize(theResource, offset+count);
  729.    }
  730.    
  731.       /*
  732.        * Check to be sure the size was successfully increased
  733.        * before continuing.
  734.        */
  735.    if (SizeResource(theResource) < offset+count) {
  736.       return ;
  737.    }
  738.    
  739.    if (partialResourceCallsAreAvailable) {
  740.       WritePartialResource(theResource, offset, buffer, count);
  741.    } else {
  742.       
  743.       long theRsrcDataOffset;
  744.       OSErr theErr;
  745.       long oldMark;
  746.       
  747.       oldMark = getRsrcFileMark(theResource);
  748.       theRsrcDataOffset = getRsrcDataOffsetIntoFile(theResource);
  749.       if (theRsrcDataOffset < 0) return;
  750.       setRsrcFileMark(theResource, theRsrcDataOffset + offset);
  751.       theErr = FSWrite( HomeResFile(theResource), &count, buffer );
  752.       setRsrcFileMark(theResource, oldMark);
  753.       
  754.    }
  755. }
  756.  
  757.  
  758.  
  759. void jSetResourceSize(Handle theResource, long size)
  760. {
  761.    if (partialResourceCallsAreAvailable == kUninitializedFlag) {
  762.       determineWhetherPRCallsAreAvailable();
  763.    }
  764.    
  765.    if (partialResourceCallsAreAvailable) {
  766.       SetResourceSize(theResource, size);
  767.    } else {
  768.       
  769.       Debugger();
  770.       
  771.    }
  772. }
  773.  
  774.  
  775.  
  776. void determineWhetherPRCallsAreAvailable(void)
  777. {
  778.    if (partialResourceCallsAreAvailable == kUninitializedFlag) {
  779.       OSErr theOSErr;
  780.       long theResponse;
  781.       partialResourceCallsAreAvailable = FALSE;
  782. #ifdef appleHadActuallyImplementedTheResourceMgrAttrSelectorInSystem7_0_x
  783.       theOSErr = Gestalt(gestaltResourceMgrAttr, &theResponse);
  784.       if (theOSErr == noErr) {
  785.          if ( (theResponse & 1L<<gestaltPartialRsrcs) != 0 ) {
  786.             partialResourceCallsAreAvailable = TRUE;
  787.          }
  788.       }
  789. #else
  790.       theOSErr = Gestalt(gestaltSystemVersion, &theResponse);
  791.       if (theOSErr == noErr) {
  792.          if ( (theResponse & 0x0000FFFF) >= 0x0700 ) {
  793.             partialResourceCallsAreAvailable = TRUE;
  794.          }
  795.       }
  796. #endif
  797.    }
  798. }
  799.  
  800.  
  801.  
  802. /******************************/
  803.  
  804.  
  805.  
  806. rsrcMapPtr getHomeRsrcMap(Handle theResource)
  807. {
  808.    rsrcMapHndl cMapHndl;
  809.    short theRefNum;
  810.    
  811.    theRefNum = HomeResFile(theResource);
  812.    cMapHndl = (rsrcMapHndl) TopMapHndl;
  813.    
  814.    while ( (**cMapHndl).fileRefNum != theRefNum ) {
  815.       cMapHndl = (**cMapHndl).nextRsrcMapHndl;
  816.       if (cMapHndl == NULL) return NULL;
  817.    }
  818.    
  819.    return *cMapHndl;
  820. }
  821.  
  822.  
  823.  
  824. long getRsrcRefOffsetIntoFile(Handle theResource)
  825. {
  826.    long offsetToRsrcRefFromRsrcMap;
  827.    long offsetToRsrcMapFromStartOfFile;
  828.    
  829.    rsrcMapPtr theRsrcMapPtr;
  830.    
  831.    ASSERT(theResource != NULL);
  832.    
  833.    offsetToRsrcRefFromRsrcMap = RsrcMapEntry(theResource);
  834.    if (offsetToRsrcRefFromRsrcMap == 0) {
  835.          /* ResError contains the error. */
  836.       return -1;
  837.    }
  838.    
  839.    theRsrcMapPtr = getHomeRsrcMap(theResource);
  840.    offsetToRsrcMapFromStartOfFile = theRsrcMapPtr->copyOfRsrcForkHeader.offsetToRsrcMap;
  841.    
  842.    return offsetToRsrcMapFromStartOfFile + offsetToRsrcRefFromRsrcMap;
  843. }
  844.  
  845.  
  846.  
  847. long getRsrcDataOffsetIntoFile(Handle theResource)
  848. {
  849.    rsrcReference theRsrcRef;
  850.    long theOffsetToRsrcRef;
  851.    long theOffsetToRsrcData;
  852.    long oldMark;
  853.    OSErr theErr;
  854.    long nBytesToRead;
  855.    
  856.    theOffsetToRsrcRef = getRsrcRefOffsetIntoFile(theResource);
  857.    
  858.    oldMark = getRsrcFileMark(theResource);
  859.    setRsrcFileMark(theResource, theOffsetToRsrcRef);
  860.    nBytesToRead = sizeof(rsrcReference);
  861.    theErr = FSRead( HomeResFile(theResource), &nBytesToRead, &theRsrcRef);
  862.    setRsrcFileMark(theResource, oldMark);
  863.    
  864.    if (theErr != noErr || nBytesToRead < sizeof(rsrcReference)) {
  865.       return -1;
  866.    }
  867.    
  868.    theOffsetToRsrcData = theRsrcRef.offsetToRsrcData
  869.       + 0x0100       // add in the length of the resource header
  870.       + 4;           // skip over the longword that tells the resource's length
  871.    return theOffsetToRsrcData;
  872. }
  873.  
  874.  
  875.  
  876. long getRsrcFileMark(Handle theResource)
  877. {
  878.    OSErr theErr;
  879.    long theMark;
  880.    ASSERT(theResource != NULL);
  881.    theErr = GetFPos( HomeResFile(theResource), &theMark );
  882.    if (theErr != noErr) theMark = -1;
  883.    return theMark;
  884. }
  885.  
  886.  
  887.  
  888. void setRsrcFileMark(Handle theResource, long newMark)
  889. {
  890.    ASSERT(theResource != NULL);
  891.    /* theOSErr = */ SetFPos( HomeResFile(theResource), fsFromStart, newMark );
  892. }
  893.  
  894. +++++++++++++++++++++++++++
  895.  
  896. From: mgleason@cse.unl.edu (Mike Gleason)
  897. Date: Fri, 25 Sep 1992 21:15:32 GMT
  898. Organization: NCEMRSoft
  899.  
  900. k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  901.  
  902. >Following is my current working version of "Jamie's Partial Resources,"
  903. >glue that makes the system-7 partial resource calls work under any
  904. >system.  I'm posting this here 'cause I haven't seen partial-resource
  905. >glue anywhere else, and I thought it might be useful.
  906.  
  907. > [code omitted]
  908.  
  909. This reminds me of a catch-22 when writing apps that run under 7.0 and 6.x.
  910. You end up using the archaic 6.x routines because 6.x doesn't have the useful
  911. 7.0 stuff, and/or writing your own version of the 7.0 stuff for the 6.x users.
  912. Prime example: the FSSpec calls in the 7.0 File Manager.  Wouldn'tcha just
  913. love to use these?  Unless you write your own glue to use FSSpecs you have
  914. to settle with using FSSpecs as variables, then passing fs.name, fs.vRefNum,
  915. and fs.parID to HOpen() instead of FSpOpenDF().
  916.  
  917. I nominate that the FSSpec calls be added to a new System version 6.1.
  918. There are probably other bits (like partial resources, even though they're
  919. not used often) that could be added to a 6.1 that wouldn't require the rest
  920. of the 7.0 OS.
  921.  
  922. - --
  923. ______________________________________________________________________________
  924. mike gleason                 mgleason@cse.unl.edu             NCEMRSoft, baby!
  925.  
  926. +++++++++++++++++++++++++++
  927.  
  928. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  929. Date: 25 Sep 92 22:59:52 GMT
  930. Organization: Kalamazoo College
  931.  
  932. mgleason@cse.unl.edu (Mike Gleason) writes:
  933. >k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  934. >
  935. >This reminds me of a catch-22 when writing apps that run under 7.0 and 6.x.
  936. >You end up using the archaic 6.x routines because 6.x doesn't have the useful
  937. >7.0 stuff, and/or writing your own version of the 7.0 stuff for the 6.x users.
  938. >
  939. >I nominate that the FSSpec calls be added to a new System version 6.1.
  940. >There are probably other bits (like partial resources, even though they're
  941. >not used often) that could be added to a 6.1 that wouldn't require the rest
  942. >of the 7.0 OS.
  943.  
  944. ...and then how many users would upgrade to 6.1?  We'd still end up
  945. having to write the dual-system code for the next n years, until a
  946. sufficiently small number of 6.0 users remained.
  947.  
  948. Ideally, Apple would release small code libraries (object code maybe?)
  949. that would do the Right Thing for things like the new FSSpec calls under
  950. both 7 and 6.  It'd save developers a lot of hassle, and would get
  951. studly products to market quicker...of course, if they'd intended to do
  952. that, they'd have done it two years ago...
  953. - -- 
  954.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  955.  I'm your only friend, I'm not your only friend, but I'm a little glowing
  956.  friend, but really I'm not actually your friend, but I am...
  957.  
  958. +++++++++++++++++++++++++++
  959.  
  960. From: sdorner@qualcomm.com (Steven Dorner)
  961. Date: 27 Sep 92 16:14:12 GMT
  962. Organization: Qualcomm, Inc
  963.  
  964. k044477@hobbes.kzoo.edu (Jamie R. McCarthy) wrote:
  965. > ...and then how many users would upgrade to 6.1?  We'd still end up
  966. > having to write the dual-system code for the next n years, until a
  967. > sufficiently small number of 6.0 users remained.
  968.  
  969. System 7 will be two years old this coming spring.  1M SIMM's are $25. 
  970. Enough is enough; I'm making one more system 6 compatible release, and then
  971. I'm simply going to forget that System 6 ever existed.
  972.  
  973. +++++++++++++++++++++++++++
  974.  
  975. From: grobbins@Apple.COM (Grobbins)
  976. Date: 27 Sep 92 22:53:38 GMT
  977. Organization: Apple Computer Inc., Cupertino, CA
  978.  
  979. In article <1992Sep25.225952.24833@hobbes.kzoo.edu> k044477@hobbes.kzoo.edu (Jamie R. McCarthy) writes:
  980. >mgleason@cse.unl.edu (Mike Gleason) writes:
  981. >>I nominate that the FSSpec calls be added to a new System version 6.1.
  982. >>There are probably other bits (like partial resources, even though they're
  983. >>not used often) that could be added to a 6.1 that wouldn't require the rest
  984. >>of the 7.0 OS.
  985. >Ideally, Apple would release small code libraries (object code maybe?)
  986. >that would do the Right Thing for things like the new FSSpec calls under
  987. >both 7 and 6.
  988.  
  989. The current interfaces do help a bit; in particular, Gestalt and
  990. FindFolder can be used without regard to the system being run
  991. because of the glue which is automatically supplied (at least
  992. by the MPW and Think C and Pascal compilers.)
  993.  
  994. If your main desire is for FSSpecs, it's easy to write wrapper
  995. functions.  Alternatively, most FSp---- and Alias Manager calls
  996. are available under System 6.0.7 if QuickTime is installed, so that
  997. is one way to modernize old system versions.
  998.  
  999. Grobbins             grobbins@apple.com
  1000.  
  1001. Usual disclaimers apply.
  1002.  
  1003. +++++++++++++++++++++++++++
  1004.  
  1005. From: peirce@outpost.SF-Bay.org (Michael Peirce)
  1006. Date: 29 Sep 92 00:06:43 GMT
  1007. Organization: Peirce Software
  1008.  
  1009.  
  1010. In article <sdorner-270992111026@dorner.slip.uiuc.edu> (comp.sys.mac.programmer), sdorner@qualcomm.com (Steven Dorner) writes:
  1011. > k044477@hobbes.kzoo.edu (Jamie R. McCarthy) wrote:
  1012. > > ...and then how many users would upgrade to 6.1?  We'd still end up
  1013. > > having to write the dual-system code for the next n years, until a
  1014. > > sufficiently small number of 6.0 users remained.
  1015. > System 7 will be two years old this coming spring.  1M SIMM's are $25. 
  1016. > Enough is enough; I'm making one more system 6 compatible release, and then
  1017. > I'm simply going to forget that System 6 ever existed.
  1018.  
  1019. My product Smoothie doesn't support System 6. It came out after System
  1020. 7 had been around a while and it takes advantage of a number of System 7
  1021. features.
  1022.  
  1023. I've yet to have anyone complain about not supporting System 6...
  1024. (no doubt I'll get a complain about 15 minutes after I post this,
  1025. but so far so good!)
  1026.  
  1027. - --  Michael Peirce      --   peirce@outpost.SF-Bay.org
  1028. - --  Peirce Software     --   Suite 301, 719 Hibiscus Place
  1029. - --                      --   San Jose, California USA 95117
  1030. - --  Makers of...        --   voice: (408) 244-6554 fax: (408) 244-6882
  1031. - --            SMOOTHIE  --   AppleLink: peirce & America Online: AFC Peirce
  1032.  
  1033. ---------------------------
  1034.  
  1035. End of C.S.M.P. Digest
  1036. **********************
  1037.